package com.controller.student;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import com.po.SorderH;
import com.service.student.SorderServiceH;
import com.service.student.SorderdishServiceH;
import com.util.TimeToStringUtil;

@Controller
public class SorderControllerH {
	
	@Resource(name="sorderServiceImpH")
	private SorderServiceH sorderservice;
	
	@Resource(name="sorderdishServiceImpH")
	private SorderdishServiceH sorderdishservice;
	
//	TimeToStringUtil time = new TimeToStringUtil();
//    String str = time.timeToString();
	
	@ResponseBody
	@RequestMapping(value="/find1")
	public List<SorderH> findOrderInfo(@RequestBody SorderH order){
		
		String student_id = order.getStudent_id();
		List<SorderH> orderinfo = sorderservice.findOrderInfo(student_id);
		return orderinfo;
	}
	
	@ResponseBody
	@RequestMapping(value="/del1")
	public int delOrder(@RequestBody SorderH order){
		
		String order_id = order.getOrder_id();
		System.out.println("order_id**************"+order_id);
		return sorderservice.delOrder(order_id);
	}
	
	@ResponseBody
	@RequestMapping(value="/add1")
	public int addOrder(@RequestBody ArrayList<SorderH> list){
		
		TimeToStringUtil time = new TimeToStringUtil();
		String str = time.timeToString();
		String str1 = time.timeToString1();
		
		list.get(0).setOrder_id(str);
		list.get(0).setOrder_appointtime(str1);
		list.get(0).setOrder_status("未接单");
		sorderservice.addOrder(list.get(0));
		
		for(int i=0;i<list.size();i++){
			
			list.get(i).setOrder_id(str);
			sorderdishservice.addOrderdish(list.get(i));
		}
		
		return 1;
	}
	
	@ResponseBody
	@RequestMapping(value="/getList1")
	public List<SorderH> getOrderList(){
		
		return (List<SorderH>) sorderservice.getOrderList();
	}
	
//	@ResponseBody
//	@RequestMapping(value="/addorder")
//	public int addOrderdish(@RequestBody SorderdishH orderdish){
//		
//		orderdish.setOrder_id(str);
//		return sorderdishservice.addOrderdish(orderdish);
//	}
}
